<?php

namespace app\adminbackstage\controller;

use app\adminbackstage\service\StoreManageService;
use app\BaseController;
use app\Response;
use think\facade\Request;

class StoreManage extends BaseController
{
    /****
     * 站点账号列表
    */
    public function StoreManageList(){
        if (Request::isPost()) {
            $page = Request::param("page",1);
            $num = Request::param("num");
            $enable = Request::param("enable");
            $phone = Request::param("phone");
            $username = Request::param("username");
            $nickname =Request::param("nickname");
            $str_time = Request::param("start_time");
            $end_time = Request::param("end_time");
            $m_account = Request::param("m_account");
            $res = StoreManageService::StoreManageListService($page,$num,$enable,$phone,$username,$nickname,$str_time,$end_time,$m_account);
            return $res;
        }
    }


    /***
     * 网点驿站  添加
    */
    public function StoreManageAdd(){
        if (Request::isPost()) {
            $data = Request::param();
            try{
                $this->validate($data, 'StoreManage');
            }catch (\Exception $e){
                return Response::wrapError(0,$e->getMessage());
            }
            $res = StoreManageService::StoreManageAddService($data);
            return $res;
        }
    }


    public function StoreManageEdit(){
        if (Request::isPost()) {
            $id = Request::param("uid");
            $enable = Request::param("enable","");
            $remarks = Request::param("remarks");
            if(is_numeric($enable)){
                if(empty($remarks)){
                    return Response::wrapError(0,"请输入操作禁用/启用原因！");
                }
            }
            $password = Request::param("password");

            $res = StoreManageService::StoreManageEditService($id,$enable,$remarks,$password);
            return $res;
        }
    }

    public function StoreManageBindList(){
        if (Request::isPost()) {
            $id = Request::param("uid");
            $page = Request::param("page",1);
            $num = Request::param('num',10);
            $res = StoreManageService::StoreManageBindListService($id,$page,$num);
            return $res;
        }
    }
}